<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Chapter 11: Associative Containers | A君的秘密基地</title><meta name="keywords" content="C++ Primer"><meta name="author" content="astralcon"><meta name="copyright" content="astralcon"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Exercises Section 11.1Ex11.112map：关联容器，元素为键值对；map没有push_back；map的元素按照关键字来保存和访问vector：顺序容器，元素为内置类型或者自定义类型；可以对vector调用排序算法；vector是按照元素在容器的位置保存和访问  Ex11.212345list：在任何位置添加和删除元素vector：随机访问，只能在尾部添加元素deque：">
<meta property="og:type" content="article">
<meta property="og:title" content="Chapter 11: Associative Containers">
<meta property="og:url" content="https://astralcon.gitee.io/blog/2022/05/14/Chapter-11-Associative-Containers/index.html">
<meta property="og:site_name" content="A君的秘密基地">
<meta property="og:description" content="Exercises Section 11.1Ex11.112map：关联容器，元素为键值对；map没有push_back；map的元素按照关键字来保存和访问vector：顺序容器，元素为内置类型或者自定义类型；可以对vector调用排序算法；vector是按照元素在容器的位置保存和访问  Ex11.212345list：在任何位置添加和删除元素vector：随机访问，只能在尾部添加元素deque：">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="">
<meta property="article:published_time" content="2022-05-14T06:27:14.000Z">
<meta property="article:modified_time" content="2022-05-14T06:57:59.636Z">
<meta property="article:author" content="astralcon">
<meta property="article:tag" content="C++ Primer">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content=""><link rel="shortcut icon" href="/blog/img/avatar.jpg"><link rel="canonical" href="https://astralcon.gitee.io/blog/2022/05/14/Chapter-11-Associative-Containers/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: {"appId":"YUB0ZFWBBL","apiKey":"78d0f1fae31a1df3e0cb573725c55558","indexName":"blog","hits":{"per_page":6},"languages":{"input_placeholder":"搜索文章","hits_empty":"找不到您查询的内容：${query}","hits_stats":"找到 ${hits} 条结果，用时 ${time} 毫秒"}},
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Chapter 11: Associative Containers',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-14 14:57:59'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.2.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/blog/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">27</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首頁</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-folder-open"></i><span> 目录</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/game/"><i class="fa-fw fas fa-gamepad"></i><span> 游戏</span></a></li><li><a class="site-page child" href="/blog/book/"><i class="fa-fw fas fa-book"></i><span> 书籍</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">A君的秘密基地</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首頁</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-folder-open"></i><span> 目录</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/blog/game/"><i class="fa-fw fas fa-gamepad"></i><span> 游戏</span></a></li><li><a class="site-page child" href="/blog/book/"><i class="fa-fw fas fa-book"></i><span> 书籍</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Chapter 11: Associative Containers</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-05-14T06:27:14.000Z" title="发表于 2022-05-14 14:27:14">2022-05-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-14T06:57:59.636Z" title="更新于 2022-05-14 14:57:59">2022-05-14</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/C/">C++</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-commentcount"><i class="far fa-comments fa-fw post-meta-icon"></i><span class="post-meta-label">评论数:</span><a href="/blog/2022/05/14/Chapter-11-Associative-Containers/#post-comment" itemprop="discussionUrl"><span class="valine-comment-count" data-xid="/blog/2022/05/14/Chapter-11-Associative-Containers/" itemprop="commentCount"></span></a></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Exercises-Section-11-1"><a href="#Exercises-Section-11-1" class="headerlink" title="Exercises Section 11.1"></a>Exercises Section 11.1</h1><h2 id="Ex11-1"><a href="#Ex11-1" class="headerlink" title="Ex11.1"></a>Ex11.1</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">map：关联容器，元素为键值对；map没有push_back；map的元素按照关键字来保存和访问</span><br><span class="line">vector：顺序容器，元素为内置类型或者自定义类型；可以对vector调用排序算法；vector是按照元素在容器的位置保存和访问</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-2"><a href="#Ex11-2" class="headerlink" title="Ex11.2"></a>Ex11.2</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">list：在任何位置添加和删除元素</span><br><span class="line">vector：随机访问，只能在尾部添加元素</span><br><span class="line">deque：随机访问，只能在首尾添加元素</span><br><span class="line">map：键值对的集合</span><br><span class="line">set：关键字即为值</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-3"><a href="#Ex11-3" class="headerlink" title="Ex11.3"></a>Ex11.3</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    map&lt;string, <span class="type">size_t</span>&gt; word_count;</span><br><span class="line">    string word;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; word)</span><br><span class="line">        ++word_count[word];</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;w : word_count)</span><br><span class="line">        cout &lt;&lt; w.first &lt;&lt; <span class="string">&quot; occurs &quot;</span> &lt;&lt; w.second &lt;&lt; ((w.second &gt; <span class="number">1</span>) ? <span class="string">&quot;times&quot;</span> : <span class="string">&quot;time&quot;</span>) &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-4"><a href="#Ex11-4" class="headerlink" title="Ex11.4"></a>Ex11.4</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;string&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    map&lt;string, <span class="type">size_t</span>&gt; word_count;</span><br><span class="line">    string word;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; word)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span> (<span class="built_in">isupper</span>(word[<span class="number">0</span>]))</span><br><span class="line">            word[<span class="number">0</span>] = <span class="built_in">tolower</span>(word[<span class="number">0</span>]);</span><br><span class="line">        <span class="keyword">if</span> (<span class="built_in">ispunct</span>(word[word.<span class="built_in">size</span>() - <span class="number">1</span>]))</span><br><span class="line">            word.<span class="built_in">pop_back</span>();</span><br><span class="line">        ++word_count[word];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;w : word_count)</span><br><span class="line">        cout &lt;&lt; w.first &lt;&lt; <span class="string">&quot; occurs &quot;</span> &lt;&lt; w.second &lt;&lt; ((w.second &gt; <span class="number">1</span>) ? <span class="string">&quot;times&quot;</span> : <span class="string">&quot;time&quot;</span>) &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="Exercises-Section-11-2-1"><a href="#Exercises-Section-11-2-1" class="headerlink" title="Exercises Section 11.2.1"></a>Exercises Section 11.2.1</h1><h2 id="Ex11-5"><a href="#Ex11-5" class="headerlink" title="Ex11.5"></a>Ex11.5</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">map：保存的元素为键值对，需要使用关键字查找值时使用 map</span><br><span class="line">set：保存的元素为关键字，关键字也即是值</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-6"><a href="#Ex11-6" class="headerlink" title="Ex11.6"></a>Ex11.6</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">set：关联容器，可以判断给定的值是否存在</span><br><span class="line">list：顺序容器，可以顺序访问元素</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-7"><a href="#Ex11-7" class="headerlink" title="Ex11.7"></a>Ex11.7</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;vector&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">add_family</span><span class="params">(map&lt;string, vector&lt;string&gt;&gt; &amp;families, <span class="type">const</span> string &amp;family)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (families.<span class="built_in">find</span>(family) == families.<span class="built_in">end</span>())</span><br><span class="line">        families[family] = <span class="built_in">vector</span>&lt;string&gt;();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">add_kid</span><span class="params">(map&lt;string, vector&lt;string&gt;&gt; &amp;families, <span class="type">const</span> string &amp;family, <span class="type">const</span> string kid)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    families[family].<span class="built_in">push_back</span>(kid);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    map&lt;string, vector&lt;string&gt;&gt; families;</span><br><span class="line">    <span class="built_in">add_family</span>(families, <span class="string">&quot;Smith&quot;</span>);</span><br><span class="line">    <span class="built_in">add_kid</span>(families, <span class="string">&quot;Smith&quot;</span>, <span class="string">&quot;John&quot;</span>);</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;f : families)</span><br><span class="line">    &#123;</span><br><span class="line">        cout &lt;&lt; f.first &lt;&lt; <span class="string">&quot;: &quot;</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;c : f.second)</span><br><span class="line">            cout &lt;&lt; c &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">        cout &lt;&lt; endl;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-8"><a href="#Ex11-8" class="headerlink" title="Ex11.8"></a>Ex11.8</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// vector 需要判断是否有重复元素而 set 不需要</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;algorithm&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    vector&lt;string&gt; words;</span><br><span class="line">    string word;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; word)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span> (<span class="built_in">find</span>(words.<span class="built_in">cbegin</span>(), words.<span class="built_in">cend</span>(), word) == words.<span class="built_in">cend</span>())   </span><br><span class="line">            words.<span class="built_in">push_back</span>(word);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;w : words)</span><br><span class="line">        cout &lt;&lt; w &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">    cout &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="Exercises-Section-11-2-2"><a href="#Exercises-Section-11-2-2" class="headerlink" title="Exercises Section 11.2.2"></a>Exercises Section 11.2.2</h1><h2 id="Ex11-9"><a href="#Ex11-9" class="headerlink" title="Ex11.9"></a>Ex11.9</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;list&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    map&lt;string, list&lt;<span class="type">int</span>&gt;&gt; word_line;</span><br><span class="line">    string word;</span><br><span class="line">    <span class="type">int</span> number;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; word &gt;&gt; number)</span><br><span class="line">        word_line[word].<span class="built_in">push_back</span>(number);</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;w : word_line)</span><br><span class="line">    &#123;</span><br><span class="line">        cout &lt;&lt; w.first &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;c : w.second)</span><br><span class="line">            cout &lt;&lt; c &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">        cout &lt;&lt; endl;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-10"><a href="#Ex11-10" class="headerlink" title="Ex11.10"></a>Ex11.10</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">map的关键字必须支持 &lt; 操作，vector 支持 &lt; 操作，故而可以定义 vector&lt;<span class="type">int</span>&gt;::iterator 到 <span class="type">int</span> 的 map；</span><br><span class="line">而 list 不支持 &lt; 操作，故而不能定义 list&lt;<span class="type">int</span>&gt;::iterator 到 <span class="type">int</span> 的 map</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-11"><a href="#Ex11-11" class="headerlink" title="Ex11.11"></a>Ex11.11</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">typedef</span> <span class="title">bool</span><span class="params">(*pf)</span><span class="params">(<span class="type">const</span> Sales_data &amp;, <span class="type">const</span> Sales_data &amp;)</span></span>;</span><br><span class="line"><span class="function">multiset&lt;Sales_data, pf&gt; <span class="title">bookstore</span><span class="params">(compareIsbn)</span></span>;</span><br></pre></td></tr></table></figure>

<h1 id="Exercises-Section-11-2-3"><a href="#Exercises-Section-11-2-3" class="headerlink" title="Exercises Section 11.2.3"></a>Exercises Section 11.2.3</h1><h2 id="Ex11-12"><a href="#Ex11-12" class="headerlink" title="Ex11.12"></a>Ex11.12</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;utility&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;vector&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    vector&lt;pair&lt;string, <span class="type">int</span>&gt;&gt; vec;</span><br><span class="line">    string word;</span><br><span class="line">    <span class="type">int</span> num;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; word &gt;&gt; num)</span><br><span class="line">        vec.<span class="built_in">push_back</span>(<span class="built_in">make_pair</span>(word, num));</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;v: vec)</span><br><span class="line">        cout &lt;&lt; v.first &lt;&lt; <span class="string">&quot; &quot;</span> &lt;&lt; v.second &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-13"><a href="#Ex11-13" class="headerlink" title="Ex11.13"></a>Ex11.13</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;utility&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="function">pair&lt;string, <span class="type">int</span>&gt; <span class="title">p1</span><span class="params">(<span class="string">&quot;Hello&quot;</span>, <span class="number">1</span>)</span></span>;</span><br><span class="line">    pair&lt;string, <span class="type">int</span>&gt; p2 = &#123;<span class="string">&quot;world&quot;</span>, <span class="number">2</span>&#125;;</span><br><span class="line">    pair&lt;string, <span class="type">int</span>&gt; p3 = <span class="built_in">make_pair</span>(<span class="string">&quot;astral&quot;</span>, <span class="number">3</span>);</span><br><span class="line">    cout &lt;&lt; p1.first &lt;&lt; <span class="string">&quot; &quot;</span> &lt;&lt; p1.second &lt;&lt; endl;</span><br><span class="line">    cout &lt;&lt; p2.first &lt;&lt; <span class="string">&quot; &quot;</span> &lt;&lt; p2.second &lt;&lt; endl;</span><br><span class="line">    cout &lt;&lt; p3.first &lt;&lt; <span class="string">&quot; &quot;</span> &lt;&lt; p3.second &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-14"><a href="#Ex11-14" class="headerlink" title="Ex11.14"></a>Ex11.14</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;vector&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;utility&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">add_family</span><span class="params">(map&lt;string, vector&lt;pair&lt;string, string&gt;&gt;&gt; &amp;families, <span class="type">const</span> string &amp;family)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (families.<span class="built_in">find</span>(family) == families.<span class="built_in">end</span>())</span><br><span class="line">        families[family] = vector&lt;pair&lt;string, string&gt;&gt;();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">add_kid</span><span class="params">(map&lt;string, vector&lt;pair&lt;string, string&gt;&gt;&gt; &amp;families, <span class="type">const</span> string &amp;family, <span class="type">const</span> pair&lt;string, string&gt; kid)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    families[family].<span class="built_in">push_back</span>(kid);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    map&lt;string, vector&lt;pair&lt;string, string&gt;&gt;&gt; families;</span><br><span class="line">    <span class="built_in">add_family</span>(families, <span class="string">&quot;Smith&quot;</span>);</span><br><span class="line">    <span class="built_in">add_kid</span>(families, <span class="string">&quot;Smith&quot;</span>, <span class="built_in">make_pair</span>(<span class="string">&quot;John&quot;</span>, <span class="string">&quot;1995-11-11&quot;</span>));</span><br><span class="line">    <span class="built_in">add_kid</span>(families, <span class="string">&quot;Smith&quot;</span>, <span class="built_in">make_pair</span>(<span class="string">&quot;Mike&quot;</span>, <span class="string">&quot;1996-12-12&quot;</span>));</span><br><span class="line">    <span class="built_in">add_family</span>(families, <span class="string">&quot;Mikse&quot;</span>);</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;f : families)</span><br><span class="line">    &#123;</span><br><span class="line">        cout &lt;&lt; f.first &lt;&lt; <span class="string">&quot;: &quot;</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;c : f.second)</span><br><span class="line">            cout &lt;&lt; c.first &lt;&lt; <span class="string">&quot;,&quot;</span> &lt;&lt; c.second &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">        cout &lt;&lt; endl;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="Exercises-Section-11-3-1"><a href="#Exercises-Section-11-3-1" class="headerlink" title="Exercises Section 11.3.1"></a>Exercises Section 11.3.1</h1><h2 id="Ex11-15"><a href="#Ex11-15" class="headerlink" title="Ex11.15"></a>Ex11.15</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">map&lt;<span class="type">int</span>, vector&lt;<span class="type">int</span>&gt;&gt; map</span><br><span class="line"></span><br><span class="line">mapped_type: vector&lt;<span class="type">int</span>&gt;</span><br><span class="line">key_type: <span class="type">int</span></span><br><span class="line">value_type: pair&lt;<span class="type">const</span> <span class="type">int</span>, vector&lt;<span class="type">int</span>&gt;&gt;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-16"><a href="#Ex11-16" class="headerlink" title="Ex11.16"></a>Ex11.16</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    map&lt;string, <span class="type">int</span>&gt; map = &#123;&#123;<span class="string">&quot;Hello&quot;</span>, <span class="number">1</span>&#125;, &#123;<span class="string">&quot;World&quot;</span>, <span class="number">2</span>&#125;&#125;;</span><br><span class="line">    <span class="keyword">auto</span> it = map.<span class="built_in">begin</span>();</span><br><span class="line">    it-&gt;second = <span class="number">2</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;m : map)</span><br><span class="line">        cout &lt;&lt; m.first &lt;&lt; <span class="string">&quot; &quot;</span> &lt;&lt; m.second &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-17"><a href="#Ex11-17" class="headerlink" title="Ex11.17"></a>Ex11.17</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">multiset&lt;string&gt; c;</span><br><span class="line">vector&lt;string&gt; v;</span><br><span class="line"></span><br><span class="line"><span class="comment">// set 容器只允许读取元素，故前两个非法，后两个合法</span></span><br><span class="line"><span class="built_in">copy</span>(v.<span class="built_in">begin</span>(), v.<span class="built_in">end</span>(), <span class="built_in">inserter</span>(c, c.<span class="built_in">end</span>()));	</span><br><span class="line"><span class="built_in">copy</span>(v.<span class="built_in">begin</span>(), v.<span class="built_in">end</span>(), <span class="built_in">back_inserter</span>(c));</span><br><span class="line"><span class="built_in">copy</span>(c.<span class="built_in">begin</span>(), c.<span class="built_in">end</span>(), <span class="built_in">inserter</span>(v, v.<span class="built_in">end</span>()));</span><br><span class="line"><span class="built_in">copy</span>(c.<span class="built_in">begin</span>(), c.<span class="built_in">end</span>(), <span class="built_in">back_inserter</span>(v));</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-18"><a href="#Ex11-18" class="headerlink" title="Ex11.18"></a>Ex11.18</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pair&lt;<span class="type">const</span> string, <span class="type">size_t</span>&gt;::iterator map_it = word_count.<span class="built_in">cbegin</span>();</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-19"><a href="#Ex11-19" class="headerlink" title="Ex11.19"></a>Ex11.19</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">multiset&lt;Sales_data, <span class="title">decltype</span><span class="params">(compareIsbn)</span>*&gt; <span class="title">bookstore</span><span class="params">(compareIsbn)</span></span>;</span><br><span class="line">pair&lt;<span class="type">const</span> Sales_data, <span class="keyword">decltype</span>(compareIsbn)*&gt; iter = bookstore.<span class="built_in">begin</span>();</span><br></pre></td></tr></table></figure>

<h1 id="Exercises-Section-11-3-2"><a href="#Exercises-Section-11-3-2" class="headerlink" title="Exercises Section 11.3.2"></a>Exercises Section 11.3.2</h1><h2 id="Ex11-20"><a href="#Ex11-20" class="headerlink" title="Ex11.20"></a>Ex11.20</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    map&lt;string, <span class="type">size_t</span>&gt; word_count;</span><br><span class="line">    string word;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; word)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">auto</span> it = word_count.<span class="built_in">insert</span>(&#123;word, <span class="number">1</span>&#125;);</span><br><span class="line">        <span class="keyword">if</span> (!it.second)</span><br><span class="line">            ++it.first-&gt;second;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;w : word_count)</span><br><span class="line">        cout &lt;&lt; w.first &lt;&lt; <span class="string">&quot; occurs &quot;</span> &lt;&lt; w.second &lt;&lt; ((w.second &gt; <span class="number">1</span>) ? <span class="string">&quot;times&quot;</span> : <span class="string">&quot;time&quot;</span>) &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-21"><a href="#Ex11-21" class="headerlink" title="Ex11.21"></a>Ex11.21</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> (cin &gt;&gt; word)</span><br><span class="line">	++word_count.<span class="built_in">insert</span>(&#123;word, <span class="number">0</span>&#125;).first-&gt;second;</span><br><span class="line">    </span><br><span class="line"><span class="comment">// word_count.insert(&#123;word, 0&#125;)返回一个 pair 类型， pair.first是一个迭代器，指向具有指定关键字的元素，即word_count.insert(&#123;word, 0&#125;).first 的类型为 pair&lt;const string, size_t&gt;::iterator</span></span><br><span class="line"><span class="comment">// word_count.insert(&#123;word, 0&#125;).first-&gt;second即为 size_t 类型，若元素不在 map 中，则计数值为1；若在，则增1</span></span><br></pre></td></tr></table></figure>

<h2 id="Ex11-22"><a href="#Ex11-22" class="headerlink" title="Ex11.22"></a>Ex11.22</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">c.<span class="built_in">insert</span>(v);</span><br><span class="line">参数 v 的类型：value_type型对象，即 pair&lt;<span class="type">const</span> string, vector&lt;<span class="type">int</span>&gt;&gt;</span><br><span class="line">返回类型：pair&lt;map&lt;string, vecotr&lt;<span class="type">int</span>&gt;&gt;::iterator, <span class="type">bool</span>&gt;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-23"><a href="#Ex11-23" class="headerlink" title="Ex11.23"></a>Ex11.23</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;map&gt;</span></span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">add_kid</span><span class="params">(multimap&lt;string, string&gt; &amp;families, <span class="type">const</span> string &amp;family, <span class="type">const</span> string &amp;kid)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	families.<span class="built_in">insert</span>(&#123;family, kid&#125;);</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	multimap&lt;string, string&gt; families;</span><br><span class="line"> </span><br><span class="line">	<span class="built_in">add_kid</span>(families, <span class="string">&quot;Li&quot;</span>, <span class="string">&quot;Jim&quot;</span>);</span><br><span class="line">	<span class="built_in">add_kid</span>(families, <span class="string">&quot;Li&quot;</span>, <span class="string">&quot;Jack&quot;</span>);</span><br><span class="line">	<span class="built_in">add_kid</span>(families, <span class="string">&quot;Wang&quot;</span>, <span class="string">&quot;Lucy&quot;</span>);</span><br><span class="line"> </span><br><span class="line">	<span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;f : families) </span><br><span class="line">    &#123;</span><br><span class="line">		cout &lt;&lt; f.first &lt;&lt; <span class="string">&quot;: &quot;</span> &lt;&lt; f.second &lt;&lt; endl;</span><br><span class="line">	&#125;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="Exercises-Section-11-3-4"><a href="#Exercises-Section-11-3-4" class="headerlink" title="Exercises Section 11.3.4"></a>Exercises Section 11.3.4</h1><h2 id="Ex11-24"><a href="#Ex11-24" class="headerlink" title="Ex11.24"></a>Ex11.24</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 将关键字为0的元素的值赋值为1，如果没有则创建</span></span><br><span class="line">map&lt;<span class="type">int</span>, <span class="type">int</span>&gt; m;</span><br><span class="line">m[<span class="number">0</span>] = <span class="number">1</span>;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-25"><a href="#Ex11-25" class="headerlink" title="Ex11.25"></a>Ex11.25</h2><p>cpp</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">// 非法；v 是一个空容器，容器越界</span><br><span class="line">vector&lt;int&gt; v;</span><br><span class="line">v[0] = 1;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-26"><a href="#Ex11-26" class="headerlink" title="Ex11.26"></a>Ex11.26</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    map&lt;string, <span class="type">int</span>&gt; word_count;</span><br><span class="line">    string word;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; word)</span><br><span class="line">        ++word_count[word];</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;w : word_count)</span><br><span class="line">        cout &lt;&lt; w.first &lt;&lt; <span class="string">&quot; &quot;</span> &lt;&lt; w.second &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="Exercises-Section-11-3-5"><a href="#Exercises-Section-11-3-5" class="headerlink" title="Exercises Section 11.3.5"></a>Exercises Section 11.3.5</h1><h2 id="Ex11-27"><a href="#Ex11-27" class="headerlink" title="Ex11.27"></a>Ex11.27</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">当想要知道关键字 k 的元素数量时，使用 <span class="built_in">count</span>(k)</span><br><span class="line">当想要知道容器中是否有关键字 k 对应的元素存在时，使用 <span class="built_in">find</span>(k)</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-28"><a href="#Ex11-28" class="headerlink" title="Ex11.28"></a>Ex11.28</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;vector&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    vector&lt;<span class="type">int</span>&gt; v1 = &#123;<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>&#125;;</span><br><span class="line">    vector&lt;<span class="type">int</span>&gt; v2 = &#123;<span class="number">6</span>, <span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>, <span class="number">10</span>&#125;;</span><br><span class="line">    string s1 = <span class="string">&quot;T&quot;</span>;</span><br><span class="line">    string s2 = <span class="string">&quot;G&quot;</span>;</span><br><span class="line">    map&lt;string, vector&lt;<span class="type">int</span>&gt;&gt; m = &#123;&#123;s1, v1&#125;, &#123;s2, v2&#125;&#125;;</span><br><span class="line">    <span class="keyword">auto</span> it = m.<span class="built_in">find</span>(<span class="string">&quot;T&quot;</span>);</span><br><span class="line">    cout &lt;&lt; (*it).first &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;i : it-&gt;second)</span><br><span class="line">        cout &lt;&lt; i &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">    cout &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-29"><a href="#Ex11-29" class="headerlink" title="Ex11.29"></a>Ex11.29</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">如果给定关键字不在容器中，lower_bound 和 upper_bound 会返回相等的迭代器，指向一个不影响排序的关键字的插入位置；equal 的两个迭代器都指向关键字可以插入的位置</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-30"><a href="#Ex11-30" class="headerlink" title="Ex11.30"></a>Ex11.30</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pos.first-&gt;second：pos 是一个迭代器 pair，两个迭代器分别指向查找元素的第一个位置与最后一个查找元素之后的位置；pos.first指向第一个迭代器，解引用为其关键字，然后调用 second 为其关键字对应的值。</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-31"><a href="#Ex11-31" class="headerlink" title="Ex11.31"></a>Ex11.31</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    multimap&lt;string, string&gt; authors;</span><br><span class="line">    string s1, s2;</span><br><span class="line">    string book&#123;<span class="string">&quot;Alice&quot;</span>&#125;;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; s1 &gt;&gt; s2)</span><br><span class="line">    &#123;</span><br><span class="line">        authors.<span class="built_in">insert</span>(&#123;s1, s2&#125;);</span><br><span class="line">    &#125;</span><br><span class="line">    authors.<span class="built_in">erase</span>(book);</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;c : authors)</span><br><span class="line">        cout &lt;&lt; c.first &lt;&lt; <span class="string">&quot; &quot;</span> &lt;&lt; c.second &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-32"><a href="#Ex11-32" class="headerlink" title="Ex11.32"></a>Ex11.32</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;map&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    multimap&lt;string, string&gt; authors;</span><br><span class="line">    string s1, s2;</span><br><span class="line">    string book&#123;<span class="string">&quot;Alice&quot;</span>&#125;;</span><br><span class="line">    <span class="keyword">while</span> (cin &gt;&gt; s1 &gt;&gt; s2)</span><br><span class="line">    &#123;</span><br><span class="line">        authors.<span class="built_in">insert</span>(&#123;s1, s2&#125;);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">auto</span> it = authors.<span class="built_in">find</span>(book);</span><br><span class="line">    <span class="keyword">for</span> (; it-&gt;first == book;)</span><br><span class="line">        it = authors.<span class="built_in">erase</span>(it);</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">const</span> <span class="keyword">auto</span> &amp;c : authors)</span><br><span class="line">        cout &lt;&lt; c.first &lt;&lt; <span class="string">&quot; &quot;</span> &lt;&lt; c.second &lt;&lt; endl;</span><br><span class="line">    <span class="built_in">system</span>(<span class="string">&quot;pause&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="Exercises-Section-11-3-6"><a href="#Exercises-Section-11-3-6" class="headerlink" title="Exercises Section 11.3.6"></a>Exercises Section 11.3.6</h1><h2 id="Ex11-33"><a href="#Ex11-33" class="headerlink" title="Ex11.33"></a>Ex11.33</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;fstream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;sstream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdexcept&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;map&gt;</span></span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"> </span><br><span class="line"><span class="function">map&lt;string, string&gt; <span class="title">buildMap</span><span class="params">(ifstream &amp;map_file)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	map&lt;string, string&gt; trans_map;</span><br><span class="line">	string key, value;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">while</span> (map_file &gt;&gt; key &amp;&amp; <span class="built_in">getline</span>(map_file, value)) </span><br><span class="line">    &#123;</span><br><span class="line">		<span class="keyword">if</span> (value.<span class="built_in">size</span>() &gt; <span class="number">1</span>)</span><br><span class="line">			trans_map[key] = value.<span class="built_in">substr</span>(<span class="number">1</span>);</span><br><span class="line">		<span class="keyword">else</span> </span><br><span class="line">			<span class="keyword">throw</span> <span class="built_in">runtime_error</span>(<span class="string">&quot;no rule for &quot;</span> + key);</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">return</span> trans_map;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="type">const</span> string &amp;<span class="title">transform</span><span class="params">(<span class="type">const</span> string &amp;s, <span class="type">const</span> map&lt;string, string&gt; &amp;m)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">auto</span> map_it = m.<span class="built_in">find</span>(s);</span><br><span class="line">	<span class="keyword">if</span> (map_it != m.<span class="built_in">cend</span>())</span><br><span class="line">		<span class="keyword">return</span> map_it-&gt;second;</span><br><span class="line">	<span class="keyword">else</span></span><br><span class="line">		<span class="keyword">return</span> s;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">word_transform</span><span class="params">(ifstream &amp;map_file, ifstream &amp;input)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="keyword">auto</span> trans_map = <span class="built_in">buildMap</span>(map_file);</span><br><span class="line">	string text;</span><br><span class="line">	<span class="keyword">while</span> (<span class="built_in">getline</span>(input, text)) </span><br><span class="line">    &#123;</span><br><span class="line">		<span class="function">istringstream <span class="title">stream</span><span class="params">(text)</span></span>;</span><br><span class="line">		string word;</span><br><span class="line">		<span class="type">bool</span> firstword = <span class="literal">true</span>;</span><br><span class="line">		<span class="keyword">while</span> (stream &gt;&gt; word) </span><br><span class="line">        &#123;</span><br><span class="line">			<span class="keyword">if</span> (firstword)</span><br><span class="line">				firstword = <span class="literal">false</span>;</span><br><span class="line">			<span class="keyword">else</span></span><br><span class="line">				cout &lt;&lt; <span class="string">&quot; &quot;</span>;</span><br><span class="line">			cout &lt;&lt; <span class="built_in">transform</span>(word, trans_map);</span><br><span class="line">		&#125;</span><br><span class="line">		cout &lt;&lt; endl;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">(<span class="type">int</span> argc, <span class="type">char</span> *argv[])</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="function">ifstream <span class="title">map_file</span><span class="params">(argv[<span class="number">1</span>])</span></span>;</span><br><span class="line">	<span class="function">ifstream <span class="title">text</span><span class="params">(argv[<span class="number">2</span>])</span></span>;</span><br><span class="line">	</span><br><span class="line">	<span class="built_in">word_transform</span>(map_file, text);</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-34"><a href="#Ex11-34" class="headerlink" title="Ex11.34"></a>Ex11.34</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">使用下标替换 find，如果容器中不存在查找的关键字，那么就会使用值初始化方法构造一个 pair 放入容器中。</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-35"><a href="#Ex11-35" class="headerlink" title="Ex11.35"></a>Ex11.35</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">当关键字不在 map 中，使用 insert 和使用下标没有区别；</span><br><span class="line">当关键字在 map 中时，使用下标会用新值覆盖原有值，而 insert 会返回一个值指出插入失败。</span><br></pre></td></tr></table></figure>

<h2 id="Ex11-36"><a href="#Ex11-36" class="headerlink" title="Ex11.36"></a>Ex11.36</h2><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">buildMap 函数会使用 value.<span class="built_in">size</span>() 检查单词是否存在，如果不存在，则抛出一个异常。</span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://astralcon.gitee.io/blog">astralcon</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://astralcon.gitee.io/blog/2022/05/14/Chapter-11-Associative-Containers/">https://astralcon.gitee.io/blog/2022/05/14/Chapter-11-Associative-Containers/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://astralcon.gitee.io/blog" target="_blank">A君的秘密基地</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/C-Primer/">C++ Primer</a></div><div class="post_share"><div class="social-share" data-image="" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/gh/overtrue/share.js@master/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/blog/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/blog/img/wechat.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/blog/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/blog/img/alipay.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2022/05/14/Chapter-12-Dynamic-Memory/"><img class="prev-cover" src="" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Chapter 12: Dynamic Memory</div></div></a></div><div class="next-post pull-right"><a href="/blog/2022/05/14/Chapter-10-Generic-Algorithms/"><img class="next-cover" src="" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Chapter 10: Generic Algorithms</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2022/05/14/Chapter-1-Getting-Started/" title="Chapter 1: Getting Started"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-14</div><div class="title">Chapter 1: Getting Started</div></div></a></div><div><a href="/blog/2022/05/14/Chapter-10-Generic-Algorithms/" title="Chapter 10: Generic Algorithms"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-14</div><div class="title">Chapter 10: Generic Algorithms</div></div></a></div><div><a href="/blog/2022/05/14/Chapter-12-Dynamic-Memory/" title="Chapter 12: Dynamic Memory"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-14</div><div class="title">Chapter 12: Dynamic Memory</div></div></a></div><div><a href="/blog/2022/05/14/Chapter-13-Copy-Control/" title="Chapter 13: Copy Control"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-14</div><div class="title">Chapter 13: Copy Control</div></div></a></div><div><a href="/blog/2022/05/14/Chapter-15-Object-Oriented-Programming/" title="Chapter 15: Object-Oriented Programming"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-14</div><div class="title">Chapter 15: Object-Oriented Programming</div></div></a></div><div><a href="/blog/2022/05/14/Chapter-14-Overloaded-Operations-And-Conversions/" title="Chapter 14: Overloaded Operations And Conversions"><img class="cover" src="" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-05-14</div><div class="title">Chapter 14: Overloaded Operations And Conversions</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div><div id="comment-switch"><span class="first-comment">Valine</span><span class="switch-btn"></span><span class="second-comment">Disqus</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div><div><div id="disqus_thread"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/blog/img/avatar.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">astralcon</div><div class="author-info__description">slow is fast.</div></div><div class="card-info-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">27</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">4</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/astralcon" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:a842181471@qq.com.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">朝九晚五，健康生活！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-1"><span class="toc-number">1.</span> <span class="toc-text">Exercises Section 11.1</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-1"><span class="toc-number">1.1.</span> <span class="toc-text">Ex11.1</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-2"><span class="toc-number">1.2.</span> <span class="toc-text">Ex11.2</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-3"><span class="toc-number">1.3.</span> <span class="toc-text">Ex11.3</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-4"><span class="toc-number">1.4.</span> <span class="toc-text">Ex11.4</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-2-1"><span class="toc-number">2.</span> <span class="toc-text">Exercises Section 11.2.1</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-5"><span class="toc-number">2.1.</span> <span class="toc-text">Ex11.5</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-6"><span class="toc-number">2.2.</span> <span class="toc-text">Ex11.6</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-7"><span class="toc-number">2.3.</span> <span class="toc-text">Ex11.7</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-8"><span class="toc-number">2.4.</span> <span class="toc-text">Ex11.8</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-2-2"><span class="toc-number">3.</span> <span class="toc-text">Exercises Section 11.2.2</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-9"><span class="toc-number">3.1.</span> <span class="toc-text">Ex11.9</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-10"><span class="toc-number">3.2.</span> <span class="toc-text">Ex11.10</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-11"><span class="toc-number">3.3.</span> <span class="toc-text">Ex11.11</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-2-3"><span class="toc-number">4.</span> <span class="toc-text">Exercises Section 11.2.3</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-12"><span class="toc-number">4.1.</span> <span class="toc-text">Ex11.12</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-13"><span class="toc-number">4.2.</span> <span class="toc-text">Ex11.13</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-14"><span class="toc-number">4.3.</span> <span class="toc-text">Ex11.14</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-3-1"><span class="toc-number">5.</span> <span class="toc-text">Exercises Section 11.3.1</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-15"><span class="toc-number">5.1.</span> <span class="toc-text">Ex11.15</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-16"><span class="toc-number">5.2.</span> <span class="toc-text">Ex11.16</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-17"><span class="toc-number">5.3.</span> <span class="toc-text">Ex11.17</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-18"><span class="toc-number">5.4.</span> <span class="toc-text">Ex11.18</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-19"><span class="toc-number">5.5.</span> <span class="toc-text">Ex11.19</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-3-2"><span class="toc-number">6.</span> <span class="toc-text">Exercises Section 11.3.2</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-20"><span class="toc-number">6.1.</span> <span class="toc-text">Ex11.20</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-21"><span class="toc-number">6.2.</span> <span class="toc-text">Ex11.21</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-22"><span class="toc-number">6.3.</span> <span class="toc-text">Ex11.22</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-23"><span class="toc-number">6.4.</span> <span class="toc-text">Ex11.23</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-3-4"><span class="toc-number">7.</span> <span class="toc-text">Exercises Section 11.3.4</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-24"><span class="toc-number">7.1.</span> <span class="toc-text">Ex11.24</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-25"><span class="toc-number">7.2.</span> <span class="toc-text">Ex11.25</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-26"><span class="toc-number">7.3.</span> <span class="toc-text">Ex11.26</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-3-5"><span class="toc-number">8.</span> <span class="toc-text">Exercises Section 11.3.5</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-27"><span class="toc-number">8.1.</span> <span class="toc-text">Ex11.27</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-28"><span class="toc-number">8.2.</span> <span class="toc-text">Ex11.28</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-29"><span class="toc-number">8.3.</span> <span class="toc-text">Ex11.29</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-30"><span class="toc-number">8.4.</span> <span class="toc-text">Ex11.30</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-31"><span class="toc-number">8.5.</span> <span class="toc-text">Ex11.31</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-32"><span class="toc-number">8.6.</span> <span class="toc-text">Ex11.32</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Exercises-Section-11-3-6"><span class="toc-number">9.</span> <span class="toc-text">Exercises Section 11.3.6</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-33"><span class="toc-number">9.1.</span> <span class="toc-text">Ex11.33</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-34"><span class="toc-number">9.2.</span> <span class="toc-text">Ex11.34</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-35"><span class="toc-number">9.3.</span> <span class="toc-text">Ex11.35</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Ex11-36"><span class="toc-number">9.4.</span> <span class="toc-text">Ex11.36</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/blog/2022/05/17/%E3%80%8A%E7%AE%97%E6%B3%95%E8%AE%BE%E8%AE%A1%E6%89%8B%E5%86%8C%E3%80%8B%E9%9D%A2%E8%AF%95%E9%A2%98%EF%BC%9AChapter-1/" title="《算法设计手册》面试题：Chapter 1">《算法设计手册》面试题：Chapter 1</a><time datetime="2022-05-17T07:35:05.000Z" title="发表于 2022-05-17 15:35:05">2022-05-17</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/blog/2022/05/14/Wireshark-Lab-DHCP-v7-0/" title="Wireshark Lab: DHCP v7.0">Wireshark Lab: DHCP v7.0</a><time datetime="2022-05-14T07:19:53.000Z" title="发表于 2022-05-14 15:19:53">2022-05-14</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/blog/2022/05/14/Wireshark-Lab-Ethernet-and-ARP-v7-0/" title="Wireshark Lab: Ethernet and ARP v7.0">Wireshark Lab: Ethernet and ARP v7.0</a><time datetime="2022-05-14T07:18:10.000Z" title="发表于 2022-05-14 15:18:10">2022-05-14</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/blog/2022/05/14/Wireshark-Lab-ICMP-v7-0/" title="Wireshark Lab: ICMP v7.0">Wireshark Lab: ICMP v7.0</a><time datetime="2022-05-14T07:16:41.000Z" title="发表于 2022-05-14 15:16:41">2022-05-14</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/blog/2022/05/14/Wireshark-Lab-NAT-v7-0/" title="Wireshark Lab: NAT v7.0">Wireshark Lab: NAT v7.0</a><time datetime="2022-05-14T07:15:13.000Z" title="发表于 2022-05-14 15:15:13">2022-05-14</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2022 By astralcon</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="algolia-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="search-wrap"><div id="algolia-search-input"></div><hr/><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-info"><div class="algolia-stats"></div><div class="algolia-poweredBy"></div></div></div></div></div><div id="search-mask"></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js"></script><script src="/blog/js/search/algolia.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'Uh3CYGE2t1Eaz4KoTkyVQv1N-gzGzoHsz',
      appKey: '1Gdg4rGlmT4Dcfv7oNiCH1q3',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !false) {
  if (false) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script><script>function loadDisqus () {
  var disqus_config = function () {
    this.page.url = 'https://astralcon.gitee.io/blog/2022/05/14/Chapter-11-Associative-Containers/'
    this.page.identifier = '2022/05/14/Chapter-11-Associative-Containers/'
    this.page.title = 'Chapter 11: Associative Containers'
  };

  window.disqusReset = () => {
    DISQUS.reset({
      reload: true,
      config: disqus_config
    })
  }

  if (window.DISQUS) disqusReset()
  else {
    (function() { 
      var d = document, s = d.createElement('script');
      s.src = 'https://.disqus.com/embed.js';
      s.setAttribute('data-timestamp', +new Date());
      (d.head || d.body).appendChild(s);
    })();
  }
}

if ('Valine' === 'Disqus' || !false) {
  if (false) btf.loadComment(document.getElementById('disqus_thread'), loadDisqus)
  else loadDisqus()
} else {
  function loadOtherComment () {
    loadDisqus()
  }
}
</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="/blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body></html>